home *** CD-ROM | disk | FTP | other *** search
Text File | 1994-10-05 | 4.9 KB | 204 lines | [TEXT/MMCC] |
- /*================================================================================
- Zawphing
-
- ©1994 Greg Anderson
- greggor@apple.com
-
- A program that sends events to the Finder
-
- ================================================================================*/
- #include <GestaltEqu.h>
- #include <Palettes.h>
-
- #include "Main.h"
- #include "TricksDialog.h"
-
- #include "MenuHandler.h"
- #include "EventHandler.h"
-
- #include "MacUtilities.h"
- #include "DialogUtilities.h"
- #include "AppleEventUtilities.h"
- #include "Exceptions.h"
-
- //
- // Prototypes for private functions:
- //
- void InitAll(void);
- pascal OSErr QuitApplicationEvent(TAEvent& ae, TAEvent& reply, long refCon);
-
- //
- // Globals defined in this file:
- //
- Rect gUniverseRect;
- RgnHandle gUniverseRgn = nil;
- RgnHandle gScratchRgn = nil;
- GrafPtr gWindowMgrPort = nil;
-
- SysEnvRec gThisMacintosh;
- Boolean gHasAppleEvents;
- Boolean gApplicationShouldQuit = false;
-
- #if USESROUTINEDESCRIPTORS
- static RoutineDescriptor gQuitApplicationHandlerRD = BUILD_ROUTINE_DESCRIPTOR(uppAEEventHandlerProcInfo, QuitApplicationEvent);
- #endif
-
- //----------------------------------------------------------------------------------------
- // main:
- //----------------------------------------------------------------------------------------
- void main()
- {
- RgnHandle mouseRegion;
- AppFile theFile;
- DialogPtr splash;
- short preLoadFiles;
- short message;
- short i;
- OSErr err = noErr;
-
- //
- // Initialize all of the ToolBox managers, change the cursor
- // shape to a watch and display the splash screen.
- //
- InitAll();
- ChangeCursor( watchCursor );
- SetupMenuBar(1001, 1002);
-
- /*
- // Schlep together our command table
- //
- // (command ID, menu ID, item #)
- */
- AddItemIDtoTable( 1, 2, 3 );
- AddItemIDtoTable( 2, 2, 1 );
-
- //
- // Every high-level-event-aware application needs a
- // quit-application handler; otherwise, it won't quit
- // when the machine is shut down (for example)
- //
- #if USESROUTINEDESCRIPTORS
- AEInstallEventHandler(kCoreEventClass, kAEQuitApplication, &gQuitApplicationHandlerRD, 0, false);
- #else
- AEInstallEventHandler(kCoreEventClass, kAEQuitApplication, (AEEventHandlerProcPtr) &QuitApplicationEvent, 0, false);
- #endif
-
- //
- // Set the cursor back to an arrow
- //
- InitCursor();
-
- //
- // Set up the initial mouse region
- //
- mouseRegion = NewRgn();
-
- //
- // Set up a failure handler for failures that are not
- // trapped elsewhere
- //
- Try
- {
- //
- // When the program begins, open our dialog box.
- // If the dialog is ever closed, we will quit (DA model)
- //
- OpenTricksDialog();
-
- //
- // Live here until the 'gApplicationShouldQuit' flag
- // becomes true
- //
- while(gApplicationShouldQuit == false)
- HandleEvents(mouseRegion);
- }
- Catch(err)
- {
- //
- // We don't expect to ever get here...
- //
- }
- } // main
-
- //----------------------------------------------------------------------------------------
- // InitAll:
- //
- // Initialize various Macintosh managers
- //----------------------------------------------------------------------------------------
- void InitAll()
- {
- OSErr theErr;
- long heapSpace;
- Ptr appLimit;
- THz appBase;
- long gestaltResult;
- short callsToMoreMasters = 10;
-
- appBase = ApplicZone();
- appLimit = GetApplLimit();
- heapSpace = FreeMem();
- MaxApplZone();
- appLimit = GetApplLimit();
- heapSpace = FreeMem();
- while( callsToMoreMasters-- )
- MoreMasters();
-
- InitGraf(&qd.thePort);
- InitFonts();
- FlushEvents(everyEvent, 0);
- InitWindows();
- InitMenus();
- TEInit();
- InitDialogs(0L);
-
- //
- // Get the SysEnvirons record
- //
- SysEnvirons( 1, &gThisMacintosh );
-
- //
- // Check to see if AppleEvents are available
- //
- theErr = Gestalt( gestaltAppleEventsAttr, &gestaltResult );
- gHasAppleEvents = ( (theErr == noErr) && ((gestaltResult & (1L << gestaltAppleEventsPresent)) != 0) );
-
- //
- // Set a global rectangle to hold the extent of QuickDraw workspace
- // (Note: QuickDraw coordinates range from +-32767, but there
- // are bugs in QuickDraw that make it inadvisable to go beyond
- // +-16000 or so.)
- //
- SetRect(&gUniverseRect,-16000,-16000,16000,16000);
- gUniverseRgn = NewRgn();
- RectRgn(gUniverseRgn, &gUniverseRect);
- gScratchRgn = NewRgn();
- GetPort(&gWindowMgrPort);
- } // InitAll
-
- //----------------------------------------------------------------------------------------
- // ExitProgram:
- //----------------------------------------------------------------------------------------
- OSErr ExitProgram(CWindowPtr window, short item)
- {
- //
- // A "real" program would try to close all of its windows
- // first (give the user a chance to cancel)
- //
- gApplicationShouldQuit = true;
-
- return noErr;
- } // ExitProgram
-
- //----------------------------------------------------------------------------------------
- // QuitApplicationEvent:
- //----------------------------------------------------------------------------------------
- pascal OSErr QuitApplicationEvent(TAEvent& ae, TAEvent& reply, long refCon)
- {
- //
- // You should never call ExitToShell from an AppleEvent handler
- //
- gApplicationShouldQuit = true;
-
- return noErr;
- }
-